package com.car.utils;


import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;

public class JDBCUtil {
    private static DataSource dataSource;

    static {
        try {
            //创建一个properties
            Properties p = new Properties();
            //获取文件
            InputStream in = JDBCUtil.class.getClassLoader().getResourceAsStream("SqlConfig.properties");
            //载入
            p.load(in);
            //通过druidfactory获取连接池对象
            dataSource = DruidDataSourceFactory.createDataSource(p);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //提供一个方法获取连接池
    public static DataSource getDs() {
        return dataSource;
    }

    //获取32位随机字符串
    public static String getId() {
        return UUID.randomUUID().toString().replace("-","");
    }
}
